package tech.treec.smartlight;

import android.app.Application;

import android.util.Log;

import com.young.mylib.CrashUtils;
import com.young.mylib.db.DatabaseUtils;
import com.young.mylib.utils.FileUtils;
import com.young.mylib.utils.Log4AUtils;
import com.young.mylib.utils.PreferenceUtil;

import org.slf4j.LoggerFactory;

import java.util.logging.LogManager;
import java.util.logging.Logger;


/**
 * Created by Young on 2018/5/10.
 */

public class MyApplication extends Application {
    private static final String TAG = "MyApplication";
    private static MyApplication mInstance;
    public String settingFileName;
  //  private  final Logger logger = LogManager.getLogger(MyApplication.class.getName());


    public static MyApplication getInstance() {
        Log.i(TAG,"MyApplication START");
        if (mInstance == null) {
            mInstance = new MyApplication();
        }
        return mInstance;

    }


    @Override
    public void onCreate() {
        super.onCreate();
//        ch.qos.logback.classic.LoggerContext loggerContext = (ch.qos.logback.classic.LoggerContext) LoggerFactory.getILoggerFactory();
//        loggerContext.reset(); // 重置 Logback 的默认配置

        new CrashUtils(getApplicationContext()).init();
        new Log4AUtils(getApplicationContext()).init();
        new PreferenceUtil(getApplicationContext());
        Log.i(TAG,"MyApplication onCreate");
        Log4AUtils.info("MyApplication onCreate");
        mInstance = this;
        Log.i(TAG, FileUtils.getSettingPath("smartRoom"));
        settingFileName = FileUtils.getSettingPath("smartRoom") + "setting.json";
        DatabaseUtils.initHelper(getApplicationContext(),"smartLight.db");
        //  FileUtils.deleteFile(settingFileName);
        // 检查并请求存储权限
//        System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // 设置读取超时时间
//        System.setProperty("sun.net.client.defaultConnectTimeout", "30000"); // 设置连接超时时间
    }

}
